<template>
  <div class="test">
  <div class="header">
    <i class="el-icon-edit"></i>
   <i class="el-icon-share"></i>
   <i class="el-icon-delete"></i>
   <i icon="el-icon-search"></i>
   </div>
    <!-- 按钮 -->
    <div class="btns">
      <el-button size="small" type="primary"  @click="toAdd" icon="el-icon-plus" width="300">添加角色</el-button>
    </div>
    <!--角色芬兰-->
    <el-dropdown @command="handleCommand" >
  <span class="el-dropdown-link" >
    管理员<i class="el-icon-arrow-down el-icon--right" width="25%"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
     <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="角色名称" width="300"> </el-table-column>
      <el-table-column prop="address" label="  "></el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope"> 
        <el-popconfirm>  
           <el-button size="small" slot="reference"  @click="del(scope.row)">删除</el-button>
        </el-popconfirm>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dropdown-menu>
</el-dropdown>
<!--角色芬兰-->
    <el-dropdown @command="handleCommand">
  <span class="el-dropdown-link">
    学校<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
     <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="角色名称" width="300"> </el-table-column>
      <el-table-column prop="address" label="  "></el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope"> 
        <el-popconfirm>  
           <el-button size="small" slot="reference"  @click="del(scope.row)">删除</el-button>
        </el-popconfirm>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dropdown-menu>
</el-dropdown>
<!--角色芬兰-->
    <el-dropdown @command="handleCommand" >
  <span class="el-dropdown-link">
    用户<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
     <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="角色名称" width="300"> </el-table-column>
      <el-table-column prop="address" label="  "></el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope"> 
        <el-popconfirm>  
           <el-button size="small" slot="reference"  @click="del(scope.row)">删除</el-button>
        </el-popconfirm>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dropdown-menu>
</el-dropdown>
<!--角色芬兰-->
    <el-dropdown @command="handleCommand" >
  <span class="el-dropdown-link">
    观看<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
     <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="角色名称" width="300"> </el-table-column>
      <el-table-column prop="address" label="  "></el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope"> 
        <el-popconfirm>  
           <el-button size="small" slot="reference"  @click="del(scope.row)">删除</el-button>
        </el-popconfirm>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dropdown-menu>
</el-dropdown>
    <!-- 表格 -->
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="角色名称" width="300"> </el-table-column>
      <el-table-column prop="address" label="  "></el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope">
           <el-button size="small" slot="reference"  @click="del(scope.row)">删除</el-button>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog
      class="customer_modal"
      title="添加角色"
      :visible.sync="dialogVisible"
      width="60%">
      {{form}}
      <el-form :model="form" label-width="100px">
        <el-form-item label="角色id" >
          <el-input v-model="form.id"></el-input>
        </el-form-item>
        <el-form-item label="角色名称" >
          <el-input v-model="form.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save" size="small">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>


<script>

// 导入request , 浏览器提供给我们的用于与后台进行交互的工具 api
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
      form:{},
      list:[],
      dialogVisible:false,
    }
  },
  created(){
    this.loadData();
  },
  methods:{
   // 保存
    save(){
      let url = "/cms_role/saveOrUpdate"
      post(url,this.form).then( (response)=>{
        // 1. 模态框关闭
        this.dialogVisible = false;
        // 2. 提示
        this.$message({type:"success",message:response.message})
        // 3. 刷新
        this.loadData();
      } )
    },
    // 删除
    del(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = "/cms_role/delete"
          get(url,{id:row.id}).then( (response)=>{
            // 1. 提示
            this.$message({type:"success",message:response.message})
            // 2. 刷新 
            this.loadData();
          } )
        })
    },
    // 编辑
    edit(row){
      this.form = row;
      this.dialogVisible = true;
    },
    // 加载数据
    loadData(){
      let url = "/cms_rofindAll";
      get(url).then( (response)=>{
        // response就是后端返回给我们的Message{status,message,data,timestamp}
        this.list = response.data;
      } );
    },
    toAdd(){
      this.dialogVisible = true;
    },
     handleCommand(command) {
        this.$message('click on item ' + command);
      }
  }
}
</script>
<style scoped>
.header{
  float: right;
}
</style>
<style>
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
